package com.xzmzhp.utils;

import com.xzmzhp.constant.ReturnConstant;
import com.xzmzhp.dao.people.PersonnelMapper;
import com.xzmzhp.pojo.people.Personnel;
import com.xzmzhp.utils.return_tool.ReturnData;
import lombok.Data;

import java.util.List;

/**
 * @author 王源(xm)
 * @Date: 2021/9/13/ 09:40:41
 * @Description: 部门工具类
 */
@Data
public class CompetenceUtils {
    /**
     * 社长ID
     */
    private static final Integer PRESIDENT = 1;

    /**
     * 副社长ID
     */
    private static final Integer DEPUTY_HEAD = 2;

    /**
     * 部长ID
     */
    private static final Integer MINISTER = 3;

    /**
     * 本届社长人数
     */
    private static final int PRESIDENT_SIZE = 1;

    /**
     * 本届副社长人数
     */
    private static final int DEPUTY_HEAD_SIZE = 2;

    /**
     * 本届部长人数
     */
    private static final int MINISTER_SIZE = 2;

    /**
     * 判断职位 若为社长且数据库中不存在本年级社长 则添加 若为副社则超过两位 部长不超过两位
     *
     * @param personnel       人员信息类
     * @param personnelMapper 人员信息操作类
     * @return 错误信息
     */
    public ReturnData promotion(Personnel personnel, PersonnelMapper personnelMapper) {
        //判断是否为社长
        if (PRESIDENT.equals(personnel.getCompetenceId())) {
            List<Personnel> list = personnelMapper.checkPersonnel(PRESIDENT, 0, personnel.getPersonnelGrade(), 0);
            if (list.size() == PRESIDENT_SIZE) {
                return ReturnData.error(ReturnConstant.FAIL, "本届社长已存在，难道你想谋权篡位不成");
            }
        }
        //判断是否为副社长
        else if (DEPUTY_HEAD.equals(personnel.getCompetenceId())) {
            List<Personnel> list = personnelMapper.checkPersonnel(DEPUTY_HEAD, 0, personnel.getPersonnelGrade(), 0);
            if (list.size() == DEPUTY_HEAD_SIZE) {
                return ReturnData.error(ReturnConstant.FAIL, "本届副社长已满，想篡位还不篡个高点的");
            }
        }
        //判断是否为部长
        else if (MINISTER.equals(personnel.getCompetenceId())) {
            List<Personnel> list = personnelMapper.checkPersonnel(MINISTER, personnel.getPositionId(), personnel.getPersonnelGrade(), 0);
            if (list.size() == MINISTER_SIZE) {
                return ReturnData.error(ReturnConstant.FAIL, "本部门部长已满，想篡位请另谋出路");
            }
        }
        return null;
    }

}
